package com.ruoyi.financial.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.financial.vo.FBankerVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.financial.domain.FCustOdds;
import com.ruoyi.financial.service.IFCustOddsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户赔率关联Controller
 *
 * @author ruoyi
 * @date 2025-02-06
 */
@RestController
@RequestMapping("/financial/odds")
public class FCustOddsController extends BaseController {
    @Autowired
    private IFCustOddsService fCustOddsService;

    /**
     * 查询客户赔率关联列表
     */
    @PreAuthorize("@ss.hasPermi('financial:odds:list')")
    @GetMapping("/list")
    public TableDataInfo list(FCustOdds fCustOdds) {
        startPage();
        List<FCustOdds> list = fCustOddsService.selectFCustOddsList(fCustOdds);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('financial:odds:list')")
    @GetMapping("/custOddsList/{custId}")
    public R<List<FBankerVo>> custOddsList(@PathVariable("custId")Long custId) {
        List<FBankerVo> list = fCustOddsService.selectFCustBankerOddsList(custId,getUserId());
        return R.ok(list);
    }


    /**
     * 导出客户赔率关联列表
     */
    @PreAuthorize("@ss.hasPermi('financial:odds:export')")
    @Log(title = "客户赔率关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FCustOdds fCustOdds) {
        List<FCustOdds> list = fCustOddsService.selectFCustOddsList(fCustOdds);
        ExcelUtil<FCustOdds> util = new ExcelUtil<FCustOdds>(FCustOdds.class);
        util.exportExcel(response, list, "客户赔率关联数据");
    }

    /**
     * 获取客户赔率关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('financial:odds:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fCustOddsService.selectFCustOddsById(id));
    }

    /**
     * 新增客户赔率关联
     */
    @PreAuthorize("@ss.hasPermi('financial:odds:add')")
    @Log(title = "客户赔率关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FCustOdds fCustOdds) {
        return toAjax(fCustOddsService.insertFCustOdds(fCustOdds));
    }

    /**
     * 修改客户赔率关联
     */
    @PreAuthorize("@ss.hasPermi('financial:odds:edit')")
    @Log(title = "客户赔率关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FCustOdds fCustOdds) {
        return toAjax(fCustOddsService.updateFCustOdds(fCustOdds));
    }

    /**
     * 删除客户赔率关联
     */
    @PreAuthorize("@ss.hasPermi('financial:odds:remove')")
    @Log(title = "客户赔率关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fCustOddsService.deleteFCustOddsByIds(ids));
    }
}
